//
// Created by lenovo on 2021/12/14.
//
#include "stdio.h"
//本实验有缺陷，只能用来应付老师的作业，默认newp插入到链表的第二位
struct member {
    int num;
    struct member *next;
};
typedef struct member Member;

//升序：从小到大放
int insertup(Member *head, Member *newp) {
    Member *pre, *suc;
    pre = head;//头指针
    suc = head->next;//头指针链向的下一个指针

    while (suc != NULL) {//head->next！=NUll
        if (suc->num >= newp->num)
            newp->next = head->next;
        pre = suc;//pre的next的指向suc
        suc = suc->next;
    }
    suc = newp;
    head->next = newp;


}


int Print(Member *head) {
    while (head != NULL) {
        printf("%d ", head->num);
        head = head->next;
    }

}

int Experiment8_1() {
    Member a, b, c, d, new, *head, *newp;
    a.num = 0;
    b.num = 2;
    c.num = 3;
    d.num = 4;

    head = &a;
    a.next = &b;
    b.next = &c;
    c.next = &d;

    new.num = 1;
    newp = &new;
    insertup(head, newp);
    Print(head);
}

